﻿using Shop.Models.Common;
using SqlSugar;
using System.Linq.Expressions;

namespace Shop.Interface.Repository
{
    public interface IBaseRepository
    {
        ISqlSugarClient Db { get; }
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="t">实体数据</param>
        /// <returns></returns>
        Task<bool> CreateAsync<TEntity>(TEntity t) where TEntity : class, new();
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="t">实体数据</param>
        /// <returns></returns>
        bool Update<TEntity>(TEntity t) where TEntity : class, new();
        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="t">实体数据</param>
        /// <returns></returns>
        Task<bool> DeleteAsync<TEntity>(TEntity t) where TEntity : class, new();
        /// <summary>
        /// 通过ID删除实体信息
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        Task<bool> DeleteById<TEntity>(string id) where TEntity : class, new();
        /// <summary>
        /// 通过ID获取实体数据
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <returns></returns>
        TEntity GetById<TEntity>(string id) where TEntity : class, new();

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="ids"></param>
        /// <returns></returns>
        Task<bool> BatchDelete<TEntity>(string[] ids) where TEntity : BaseId, new();
        /// <summary>
        /// 获取全部实体数据
        /// </summary>
        /// <returns></returns>
        List<TEntity> GetAll<TEntity>() where TEntity : class, new();

        /// <summary>
        /// 获取全部实体记录
        /// </summary>
        /// <returns></returns>
        long GetCount<TEntity>() where TEntity : class, new();

        /// <summary>
        /// 自定义查询条件
        /// </summary>
        /// <param name="func">查询条件</param>
        /// <returns></returns>
        List<TEntity> Querry<TEntity>(Expression<Func<TEntity, bool>> func) where TEntity : class, new();

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="page">当前页码</param>
        /// <param name="size">页面大小</param>
        /// <param name="total">总记录</param>
        /// <returns></returns>
        List<TEntity> Querry<TEntity>(int page, int size, ref int total) where TEntity : class, new();
        /// <summary>
        /// 自定义条件分页查询
        /// </summary>
        /// <param name="func">查询条件</param>
        /// <param name="page">当前页码</param>
        /// <param name="size">页面大小</param>
        /// <param name="total">总记录</param>
        /// <returns></returns>
        List<TEntity> Querry<TEntity>(Expression<Func<TEntity, bool>> func, int page, int size, ref int total) where TEntity : class, new();
    }
}
